using System.Collections.Generic;
using System.Linq;
using Headsight.BPMN2WF.BPMN.Model;
using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.BPMN.Utils;
using Headsight.BPMN2WF.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.Testing.TestObjCtors
{
    /// <summary>
    /// <see cref="BPMNFlowNodesBlock"/> <see cref="ITestObjCtor{T}"/>.
    /// </summary>
    public class BPMNProcessCtor : ITestObjCtor<BPMNFlowNodesBlock>
    {
        private readonly IList<BPMNFlowNode> _flowNodes;
        private readonly List<BPMNSequenceFlow> _seqFlows;

        public BPMNProcessCtor()
        {
            _flowNodes = new List<BPMNFlowNode>();
            _seqFlows = new List<BPMNSequenceFlow>();
        }

        public BPMNFlowNodesBlock Create()
        {
            var startNode = new BPMNFlowNodeCtor().Create();
            var arguments = new List<BPMNArgument>();
            var flowNodes = new Dictionary<BPMNFlowNode, IList<BPMNFlowNode>>();
            var seqFlows = new Dictionary<string, BPMNSequenceFlow>();

            _flowNodes.ForEach(x => flowNodes[x] = new List<BPMNFlowNode>());
            _seqFlows.ForEach(x => seqFlows[x.Id] = x);
            
            return new BPMNFlowNodesBlock(startNode, arguments, flowNodes, seqFlows);
        }

        public BPMNProcessCtor With(params BPMNFlowNode[] flowNode)
        {
            foreach (var each in flowNode)
            {
                _flowNodes.Add(each);
            }

            return this;
        }

        public BPMNProcessCtor With(BPMNSequenceFlow sequenceFlow)
        {
            _seqFlows.Add(sequenceFlow);

            return this;
        }
    }
}